home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / s3bas11.zip / DUMPMEM.BAS < prev    next >
BASIC Source File  |  1993-05-14  |  3KB  |  87 lines

  1. '*****************************************************
  2. ' This is an example of using PEEK to read the user
  3. ' specified contents of memory.  DUMPMEM.BAS
  4. ' Functionally, it is very similar to READMEM except i
  5. ' DUMPMEM is command line driven.  A user could
  6. ' easily combine the two into one program by testing
  7. ' for a command line first and then prompting for
  8. ' input if the program is run without a command line.
  9. '
  10. ' By:  George Spafford  Copyright 1993
  11. '                       All Rights Reserved
  12. '
  13. ' No external libraries are required
  14. '
  15. ' v1.0  05/01/93
  16. '
  17. '*****************************************************
  18.  
  19. DEFINT A-Z
  20.  
  21. title$ = "S3 Demo of Dumping Memory v1.0         Copyright George Spafford 04/30/93"
  22. PRINT
  23. PRINT title$
  24. PRINT
  25.  
  26. 'One neat ability of BASIC is its ability to have a hexadecimal value
  27. 'specified during input and convert it on the fly.  In this example, I
  28. 'am not performing any error trapping.  Usually, I input to a string,
  29. 'check and see if it is NULL and then exit the program.  It serves as
  30. 'a back door for users who want to exit the program.  Here, I am just
  31. 'inputting directly do an integer. If the user enters a hex value in the
  32. 'form of &Hnnnn, the program will use it.  However, if they get carried
  33. 'away, they can cause an overflow condition by exceding the bounds of
  34. 'an integer.
  35.  
  36. CL$ = LTRIM$(RTRIM$(UCASE$(COMMAND$)))
  37. IF INSTR(CL$, "?") > 0 OR CL$ = "" THEN GOTO CLHelp
  38. a = INSTR(CL$, ":")
  39. IF a = 0 THEN GOTO CLHelp
  40.  
  41. Segment = VAL(LEFT$(CL$, (a - 1)))
  42. Offset = VAL(MID$(CL$, (a + 1)))
  43. Length = 64
  44.  
  45. PRINT
  46.  
  47. DEF SEG = Segment                                   'set default segment to 0000
  48. FOR n = Offset TO (Offset + (Length - 1)) STEP 1    'start at offset and look at
  49.                                                     'at the bytes
  50.     T$ = HEX$(PEEK(n))                              'get the values at offset
  51.     IF LEN(T$) = 1 THEN T$ = "0" + T$               'HEX$ doesn't add "0" if
  52.                                                     'it is the first byte.
  53.     PRINT T$; " ";                                  'print it
  54.     CharLine = CharLine + 1                         'track hex codes one screen
  55.     IF CharLine = 8 AND Length <> 8 THEN            'if 8 codes and user wanted
  56.                                                     'more than eight, add hyphen
  57.        PRINT "- ";
  58.     END IF
  59.     IF CharLine = 16 THEN                           'if 16 codes on screen, then
  60.        PRINT                                        'do a line feed
  61.        CharLine = 0
  62.     END IF
  63. NEXT n                                      'do next n
  64. DEF SEG                                     'return to BASIC segment
  65.  
  66. PRINT
  67. END
  68.  
  69.  
  70. CLHelp:
  71.     CLS
  72.     PRINT title$
  73.     PRINT
  74.     PRINT "Usage:  DUMPMEM Segment:Offset"
  75.     PRINT
  76.     PRINT "        Segment is the memory segment"
  77.     PRINT "        Offset is the memory offset"
  78.     PRINT
  79.     PRINT "Numbers are integer by default.  To enter a hexadecimal number,"
  80.     PRINT "prefix the number with &H.  For example &H400 is 400 hex."
  81.     PRINT
  82.     PRINT "DUMPMEM will then display 64 bytes starting at the given location"
  83.     PRINT "in hexadecimal."
  84.     PRINT
  85.     END
  86.  
  87.